package o;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import androidx.core.app.NotificationCompat.d;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appmarket.service.appmgr.view.activity.AppManagerProtocol;
import com.huawei.appmarket.service.deamon.bean.DownloadHistory;
import com.huawei.appmarket.service.externalapi.view.ThirdApiActivity;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import com.huawei.hwid.core.constants.HwAccountConstants;
import o.ewm.e;
import o.ewm.i;
import o.ewm.n;

public class dvv extends dvs {

    static class a {
        public static void ˏ(SessionDownloadTask sessionDownloadTask, Context context) {
            dvt.ˏ().ॱ.add(sessionDownloadTask.ʿ());
            dko o_dko = new dko();
            cjo appManagerProtocol = new AppManagerProtocol();
            appManagerProtocol.ˊ().ˊ(true);
            o_dko.ˊ(new cjm("installmgr.activity", appManagerProtocol).ॱ(context));
            o_dko.ˋ(context.getResources().getQuantityString(i.ˊᐝ, dvt.ˏ().ॱ.size(), new Object[]{Integer.valueOf(dvt.ˏ().ॱ.size())}));
            StringBuilder stringBuilder = new StringBuilder();
            int size = dvt.ˏ().ॱ.size();
            for (int i = 0; i < size; i++) {
                String str = (String) dvt.ˏ().ॱ.get(i);
                if (!TextUtils.isEmpty(str)) {
                    if (i == size - 1) {
                        stringBuilder.append(str);
                    } else {
                        stringBuilder.append(str).append("、");
                    }
                }
            }
            o_dko.ˊ(stringBuilder.toString());
            o_dko.ˏ(20160419);
            dkk.ˊ(context, o_dko).ˎ();
        }
    }

    public dvv() {
        super(Looper.getMainLooper(), new dvn());
    }

    public void handleMessage(Message message) {
        if (message.obj == null || !(message.obj instanceof SessionDownloadTask)) {
            Logger.e("HiAppDownload", "msg.obj is null or is not SessionDownloadTask");
            return;
        }
        SessionDownloadTask sessionDownloadTask = (SessionDownloadTask) message.obj;
        if (sessionDownloadTask.ʻॱ() != 1) {
            super.handleMessage(message);
        } else {
            ˎ(message);
        }
        cdt ॱ = cdw.ˋ().ॱ(sessionDownloadTask.ʻॱ());
        if (ॱ != null) {
            ॱ.ˊ(sessionDownloadTask.ʻॱ(), sessionDownloadTask);
            if (sessionDownloadTask.ʻॱ() == 5) {
                ˊ(message);
                return;
            }
            return;
        }
        ॱ(message);
    }

    private void ˎ(Message message) {
        if (edl.ˏ().ˏॱ()) {
            dvq.ˊ(ContentManager.getInstant().getContext(), (SessionDownloadTask) message.obj, message.what);
            return;
        }
        Logger.ˎ("HiAppDownload", "can not show download button progress when updating notification flag is off");
    }

    private void ˊ(Message message) {
        SessionDownloadTask sessionDownloadTask = (SessionDownloadTask) message.obj;
        Context ˋ = ContentManager.getInstant().getContext();
        switch (message.what) {
            case -1:
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 7:
                dvq.ˊ(ˋ, sessionDownloadTask, message.what);
                return;
            case 6:
                ॱ(message, ˋ, sessionDownloadTask);
                return;
            default:
                Logger.e("HiAppDownload", "Unkonw message " + message.what + " ,taskName:" + sessionDownloadTask.ʿ());
                return;
        }
    }

    private void ॱ(Message message) {
        SessionDownloadTask sessionDownloadTask = (SessionDownloadTask) message.obj;
        Context ˋ = ContentManager.getInstant().getContext();
        switch (message.what) {
            case -1:
                ʼ(message, ˋ, sessionDownloadTask);
                return;
            case 0:
                ˏ(sessionDownloadTask);
                ˎ(message, ˋ, sessionDownloadTask);
                return;
            case 1:
                ॱ(sessionDownloadTask);
                ˏ(message, ˋ, sessionDownloadTask);
                return;
            case 2:
            case 7:
                ॱ(sessionDownloadTask);
                dvq.ˊ(ˋ, sessionDownloadTask, message.what);
                return;
            case 3:
                ˊ(sessionDownloadTask);
                ˏ(sessionDownloadTask, ˋ);
                ˊ(message, ˋ, sessionDownloadTask);
                return;
            case 4:
                ˊ(sessionDownloadTask);
                ˋ(message, ˋ, sessionDownloadTask);
                return;
            case 5:
                ˊ(sessionDownloadTask);
                ˏ(sessionDownloadTask, ˋ);
                ʽ(message, ˋ, sessionDownloadTask);
                return;
            case 6:
                ˊ(sessionDownloadTask);
                ॱ(message, ˋ, sessionDownloadTask);
                return;
            case 10:
                ˏ();
                return;
            case 11:
                ˎ();
                return;
            default:
                Logger.e("HiAppDownload", "Unkonw message " + message.what + " ,taskName:" + sessionDownloadTask.ʿ());
                return;
        }
    }

    private void ˏ(SessionDownloadTask sessionDownloadTask) {
        if (dpi.ˋ(sessionDownloadTask)) {
            dwt.ॱ().ॱ(sessionDownloadTask.ʾ(), sessionDownloadTask.ʿ());
            dwt.ॱ().ˊ();
        }
    }

    private void ॱ(SessionDownloadTask sessionDownloadTask) {
        if (dpi.ˋ(sessionDownloadTask)) {
            dwt.ॱ().ˏ(sessionDownloadTask.ʾ(), sessionDownloadTask.ʿ(), sessionDownloadTask.ʼॱ(), (long) sessionDownloadTask.ˉ());
        }
    }

    private void ˊ(SessionDownloadTask sessionDownloadTask) {
        if (dpi.ˋ(sessionDownloadTask)) {
            dwt.ॱ().ˋ(sessionDownloadTask.ʾ());
        }
    }

    private void ˏ(SessionDownloadTask sessionDownloadTask, Context context) {
        fhz ˋ = fho.ˏ().ˋ("PackageManager");
        if (ˋ != null) {
            cnt o_cnt = (cnt) ˋ.ॱ(cnt.class);
            if (o_cnt != null) {
                o_cnt.ˋ(context, sessionDownloadTask.ˊˊ());
            }
        }
    }

    private void ˏ(Message message, Context context, SessionDownloadTask sessionDownloadTask) {
        dsv.ˏ(sessionDownloadTask.ˊˊ());
        dss.ॱ().ˏ(sessionDownloadTask.ˊˊ());
        dvq.ˊ(context, sessionDownloadTask, message.what);
    }

    private void ॱ(Message message, Context context, SessionDownloadTask sessionDownloadTask) {
        dvq.ˊ(context, sessionDownloadTask, message.what);
        if (sessionDownloadTask.ˏˎ() && !TextUtils.isEmpty(sessionDownloadTask.ॱˋ())) {
            cfw.ˎ(new dvk(sessionDownloadTask, -1), new dvn());
        }
    }

    private void ˊ(Message message, Context context, SessionDownloadTask sessionDownloadTask) {
        dvq.ˊ(context, sessionDownloadTask, message.what);
    }

    private void ˋ(Message message, Context context, SessionDownloadTask sessionDownloadTask) {
        DownloadHistory downloadHistory = new DownloadHistory(sessionDownloadTask);
        downloadHistory.ॱ();
        dsv.ॱ(downloadHistory);
        dvq.ˊ(context, sessionDownloadTask, message.what);
        int ˌ = sessionDownloadTask.ˌ();
        Logger.ˎ("HiAppDownload", "dlType=" + ˌ);
        if (10 != ˌ) {
            ˏ(sessionDownloadTask, dwq.ˊ);
        } else if (epw.ॱ(context, sessionDownloadTask.ˊˊ())) {
            dwm.ॱ().ˏ(sessionDownloadTask);
        } else {
            Logger.ˎ("HiAppDownload", "isRunningForeground false");
            ˏ(sessionDownloadTask, dwr.ˋ);
        }
        if (Logger.ˎ()) {
            Logger.ˏ("HiAppDownload", "task download completed, package=" + sessionDownloadTask.ˊˊ());
        }
    }

    private void ˎ(Message message, Context context, SessionDownloadTask sessionDownloadTask) {
        dss.ॱ().ˏ(sessionDownloadTask.ˊˊ());
        dvq.ˊ(context, sessionDownloadTask, message.what);
    }

    private void ʼ(Message message, Context context, SessionDownloadTask sessionDownloadTask) {
        dvq.ˊ(context, sessionDownloadTask, message.what);
    }

    private void ʽ(Message message, Context context, SessionDownloadTask sessionDownloadTask) {
        CharSequence string;
        d dVar = new d(ContentManager.getInstant().getContext());
        dVar.ˊ(e.ॱ);
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        Request request = new Request();
        request.ˋ(drj.ॱ(sessionDownloadTask.ˊˊ()));
        request.ˏ(ContentManager.getInstant().getContext().getString(n.ˑ));
        request.ॱ(KeyAndValue.NUMBER_01);
        appDetailActivityProtocol.ˏ(request);
        Intent ॱ = new cjm("appdetail.activity", appDetailActivityProtocol).ॱ(ContentManager.getInstant().getContext());
        if (sessionDownloadTask.ˌ() == 4) {
            ॱ = new Intent(ContentManager.getInstant().getContext(), ThirdApiActivity.class);
            if (TextUtils.isEmpty(sessionDownloadTask.ॱˋ())) {
                ॱ.setAction("com.huawei.appmarket.appmarket.intent.action.AppDetail.withapp");
                ॱ.putExtra("APP_PACKAGENAME", sessionDownloadTask.ˊˊ());
            } else {
                ॱ.setAction("com.huawei.appmarket.appmarket.intent.action.AppDetail.withid");
                ॱ.putExtra("appId", sessionDownloadTask.ॱˋ());
            }
        }
        dVar.ˎ(PendingIntent.getActivity(ContentManager.getInstant().getContext(), sessionDownloadTask.ˊˊ().hashCode(), ॱ, HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR));
        String str = "";
        if (sessionDownloadTask.ᐝॱ() == 5) {
            string = context.getResources().getString(n.ˋॱ);
        } else {
            string = context.getResources().getString(n.ˊॱ);
        }
        dVar.ˏ(sessionDownloadTask.ʿ());
        dVar.ˋ((CharSequence) "");
        dVar.ˊ(string);
        dVar.ˊ(0, 0, false);
        dVar.ˊ(false);
        dVar.ˏ(true);
        dkk.ˊ(dVar, 20160812, sessionDownloadTask.ˎˎ(), sessionDownloadTask.ˊˊ());
        dvq.ˊ(context, sessionDownloadTask, message.what);
    }

    private void ˎ() {
        dvt.ˏ().ˊॱ();
    }

    private void ˏ(SessionDownloadTask sessionDownloadTask, Handler handler) {
        if (4 == sessionDownloadTask.ˊॱ()) {
            fhz ˋ = fho.ˏ().ˋ("PackageManager");
            if (ˋ != null) {
                cnw o_cnw = (cnw) ˋ.ॱ(cnw.class);
                if (o_cnw == null) {
                    Logger.e("HiAppDownload", "can not found IPackageInstaller Api");
                } else if (eqh.ˎ().ˏ()) {
                    o_cnw.ˋ(ContentManager.getInstant().getContext(), new col.e().ॱ(sessionDownloadTask.ˊˊ()).ॱ(true).ˏ(etn.ˊ(1)).ॱ(sessionDownloadTask.ʿ()).ˋ(coc.IMPORTANCE).ˏ(dwq.ˊ).ॱ());
                    dsr.ˊ().ॱ(sessionDownloadTask.ˊˊ(), sessionDownloadTask.ʿ());
                }
            } else {
                Logger.e("HiAppDownload", "can not found PackageManager module");
            }
        }
        if (!(sessionDownloadTask.ˌ() != 2 || cep.ˏ() || epv.ᐝ(ContentManager.getInstant().getContext()))) {
            ˋ(sessionDownloadTask);
            sessionDownloadTask.ˏ(3);
        }
        dsl.ˏ(sessionDownloadTask, 4 == sessionDownloadTask.ˊॱ() ? coc.IMPORTANCE : coc.NORMAL, handler);
    }

    private void ˋ(SessionDownloadTask sessionDownloadTask) {
        a.ˏ(sessionDownloadTask, ContentManager.getInstant().getContext());
    }

    private void ˏ() {
        if (epv.ᐝ(ContentManager.getInstant().getContext()) && doo.ॱॱ(ContentManager.getInstant().getContext()) && !doo.ᐝ(ContentManager.getInstant().getContext())) {
            evk.ˋ(ContentManager.getInstant().getContext(), ContentManager.getInstant().getContext().getResources().getString(n.ˋߵ), 0).ˋ();
        }
    }
}
